#include <bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define F first
#define S second
#define el '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define MAX 2147483647
#define MIN -2147483647
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1e9 + 7, N = 1e6;
void solve(){
int n, m;
cin >> n >> m;
vector<vector<char>> grid(n, vector<char>(m));
bool imp = 0;
for(int i = 0; i < n; i++){
int cnt = 0;
for(int j = 0; j < m; j++){
cin >> grid[i][j];
if(grid[i][j] != '.') cnt++;
}
if(cnt%2 != 0) imp = 1;
}
for(int j = 0; j < m; j++){
int cnt = 0;
for(int i = 0; i < n; i++)
if(grid[i][j] != '.') cnt++;
if(cnt%2 != 0) imp = 1;
}
if(imp){
cout << -1 << el;
return;
}
//rows
for(int i = 0; i < n-1; i++){
bool white = 1;
for(int j = 0; j < m; j++){
if(grid[i][j] == 'U'){
if(white) grid[i][j] = 'W', grid[i+1][j] = 'B';
else grid[i][j] = 'B', grid[i+1][j] = 'W';
white = !white;
}
}
}
//cols
for(int j = 0; j < m-1; j++){
bool white = 1;
for(int i = 0; i < n; i++){
if(grid[i][j] == 'L'){
if(white) grid[i][j] = 'W', grid[i][j+1] = 'B';
else grid[i][j] = 'B', grid[i][j+1] = 'W';
white = !white;
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++)
cout << grid[i][j];
cout << el;
}
}
int main() {
FIO
int t;
cin >> t;
while (t--)
solve();
return 0;
}
151A - Soft Drinking | 1352A - Sum of Round Numbers |
281A - Word Capitalization | 1646A - Square Counting |
266A - Stones on the Table | 61A - Ultra-Fast Mathematician |
148A - Insomnia cure | 1650A - Deletions of Two Adjacent Letters |
1512A - Spy Detected | 282A - Bit++ |
69A - Young Physicist | 1651A - Playoff |
734A - Anton and Danik | 1300B - Assigning to Classes |
1647A - Madoka and Math Dad | 710A - King Moves |
1131A - Sea Battle | 118A - String Task |
236A - Boy or Girl | 271A - Beautiful Year |
520B - Two Buttons | 231A - Team |
479C - Exams | 1030A - In Search of an Easy Problem |
158A - Next Round | 71A - Way Too Long Words |
160A - Twins | 1A - Theatre Square |
1614B - Divan and a New Project | 791A - Bear and Big Brother |